package com.bawei.lib_cache.acache

import com.baway.cache.ICache
import com.bawei.lib_base.BaseApp
import com.bawei.lib_cache.utils.ACache
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow

/**
 * Author: Jason Zhang
 * Date: 2025/9/13
 * Desc: 使用Java类ACache实现
 */
object KVCache: ICache {

    private  var mAICache=ACache.get(BaseApp.appContext)

    private val saveTime=7*24*60*60



    override fun putString(key: String, value: String) {
       mAICache.put(key,value)
    }

    override fun putInt(key: String, value: Int) {
        mAICache.put(key,value)
    }

    override fun putLong(key: String, value: Long) {
        mAICache.put(key,value,saveTime)
    }

    override fun putBool(key: String, value: Boolean) {
        mAICache.put(key,value, saveTime)
    }

    override fun getString(key: String): Flow<String> {
        return flow {
          mAICache.getAsString(key)
        }
    }

    override fun getInt(key: String): Flow<Int> {
        return flow {
            ACache.get(BaseApp.appContext).getAsString(key)
        }
    }

    override fun getLong(key: String): Flow<Long> {
        return flow {
            ACache.get(BaseApp.appContext).getAsString(key)
        }
    }

    override fun getBool(key: String): Flow<Boolean> {
        return flow {
            ACache.get(BaseApp.appContext).getAsString(key)
        }
    }


}